<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>回调</title>

    <h1>这是回调页面</h1>
</head>

<body>
<div id="callback">

</div>

</body>
<!--引入vue和axios，注意axios是居于vue的所以引入顺序应该是先引入vue，再引入axios-->
<script src="js/tools/vue/dist/vue.js"></script>
<script src="js/tools/axios/dist/axios.js"></script>
<!--这里主要是引入Vue的全局配置-->
<script src="js/tools/common.js"></script>

<script type="text/javascript">
    new Vue({
        el: '#callback',
        data: {},
        methods: {},
        mounted() {
            //解析参数对象
            let url = location.href;
            let paramObj = parseUrlParams2Obj(url);

            //获取发送请求参数
            let params = {"code":paramObj.code};
            //发起微信登录请求  调用微信登录接口
            this.$http.post("/login/wechat",params)
                .then(result=>{
                    result = result.data;
                    if(result.success){ //已经关联了 免密登录之后，需要调到主页
                        //做登录
                        //提示
                        alert("登录成功！")
                        //1.保存返回的token，logininfo到localStorage
                        let {token,logininfo} = result.resultObj;
                        localStorage.setItem("token",token);
                        localStorage.setItem("logininfo",JSON.stringify(logininfo));
                        //2.跳转到首页，显示当前登录人
                        location.href="index.html";
                    }else{
                        let {binderTmp} = result.resultObj;
                        let binderUrl =" binder.html" + binderTmp;
                        location.href = binderUrl;
                    }
                })
                .catch(result=>{
                    alert("系统错误");
                    console.log(result);
                })
        }

    })
</script>
</html>
